package cn.studyjams.s2.sj0172.wallpaper;

import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

import com.google.firebase.analytics.FirebaseAnalytics;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {
    private CheckBox mCheckVoice;
    private FirebaseAnalytics mFirebaseAnalytics;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
        setContentView(R.layout.activity_main);
        mCheckVoice = (CheckBox) findViewById(R.id.id_cb_voice);
        mCheckVoice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (isChecked) {
                    VideoWallPaperService.voiceSilence(getApplicationContext());
                } else {
                    VideoWallPaperService.voiceNormal(getApplicationContext());
                }
            }
        });
    }

    public void setVideoToWallPaper(View view) {
        VideoWallPaperService.setToWallPaper(this);
    }

    public void setGirl(View view) {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
        try {
            wallpaperManager.setResource(R.raw.girl);
            Toast.makeText(this, "美女壁纸设置成功...", Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void setNature(View view) {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
        Bitmap wallpaper = BitmapFactory.decodeResource(getResources(), R.raw.wallpaper);
        try {
            wallpaperManager.setBitmap(wallpaper);
            Toast.makeText(this, "风景壁纸设置成功...", Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void clear(View view) {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
        try {
            wallpaperManager.clear();
            Toast.makeText(this, "壁纸清除成功...", Toast.LENGTH_SHORT).show();
//            clearWallpaper();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}



